<h1>Timed Code Execution</h1>

<div id="timed-code" class="sect">
	<h2>TaskMgr &amp; TaskRunner</h2>
	<p>	
    The TaskRunner class is used to execute a function at a specified interval. This is useful when doing polling type operations, for example when
    reloading Ajax content every 30 seconds. The TaskMgr object is a singleton instance of TaskRunner, it can be used for quick access to a TaskRunner.
<pre>
var stop = false;
var task = {
    run: function(){
        if(!stop){
            alert(new Date());
        }else{
            runner.stop(task); <span class="comment">// we can stop the task here if we need to.</span>
        }
    },
    interval: 30000 <span class="comment">// every 30 seconds</span>
};
var runner = new Ext.util.TaskRunner();
runner.start(task);

<span class="comment">// Using TaskMgr</span>
Ext.TaskMgr.start({
    run: function(){
    },
    interval: 1000
});
</pre>	
	</p>
</div>

<div id="delayed-task" class="sect">
	<h2>DelayedTask</h2>
	<p>	
    The DelayedTask class provides a convenient way to "buffer" the execution of a method. When called, the task will wait the specified time period before executing.
    If durng that time period, the task is called again, the original call will be cancelled. This continues so that the function is only called a single time for each
    iteration. This method is especially useful for things like detecting whether a user has finished typing in a text field.
    
 <pre>
 var task = new Ext.util.DelayedTask(function(){
     alert(Ext.getDom('myInputField').value.length);
 });
 <span class="comment">// Wait 500ms before calling our function. If the user presses another key 
 // during that 500ms, it will be cancelled and we'll wait another 500ms.</span>
 Ext.get('myInputField').on('keypress', function(){
     task.delay(500); 
 });
 </pre>
 Note that we are using a DelayedTask here to illustrate a point. The configuration option buffer for addListener/on will also setup a delayedtask for you to buffer events.
	</p>
</div>
